package com.spark.mooc.ch5_rdd.part04_cases

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @description:
 * @time: 2020/12/16 15:29
 * @author: lhy
 */
object BookAvg {
    def main(args: Array[String]): Unit = {
        val conf = new SparkConf().setAppName("BookAvg").setMaster("local")
        val sc = new SparkContext(conf)
        val data = sc.parallelize(Array(("spark",3),("hadoop",6),("hadoop",4),("spark",6)))
        val results = data.groupByKey().mapValues(data => data.sum.toDouble / data.size)
        results.foreach(println)
    }
}
